package com.tools.function.txt;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.tools.function.R;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

public class TxtReaderDemoActivity extends Activity {

    Button btn1, btn2;
    TextView textView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_text);

        btn1 = (Button) findViewById(R.id.button1);
        btn2 = (Button) findViewById(R.id.button2);
        textView = (TextView) findViewById(R.id.textView1);
        btn1.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent intent = new Intent(TxtReaderDemoActivity.this, FileManager.class);
                startActivity(intent);
            }
        });
        btn2.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = getIntent();
                String path = intent.getStringExtra("path");
                String fileName = intent.getStringExtra("name");
                File file = new File(path);
                FileInputStream inputStream;

                try {
                    inputStream = new FileInputStream(file);
                    String string = TxtReader.getString(inputStream);
                    textView.setText(string);
                } catch (FileNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        });
    }
}